<template>
	<view class="plr-16" style="box-sizing: border-box;">
		<u-gap height="12"></u-gap>
		<w-activity-card v-for="item in pagination.data" :key="item.id" :item='item'></w-activity-card>
		<w-loading :type="loading" emptyType="search" empty-top="50"></w-loading>
	</view>
</template>

<script>
	import {
		getActivityList
	} from '@/api/news/index.js'
	const pagination = {
	  data: [],
	  current_page: 1,
	  total: 1,
	  last_page: 1,
	};
	export default {
		data() {
			return {
				pagination: {
				  data: [],
				  current_page: 1,
				  total: 1,
				  last_page: 1,
				},
				loading:'none'
			}
		},
		onLoad() {
			this.onRefresh()
		},
		onReachBottom() {
			if (this.pagination.current_page < this.pagination.last_page) {
			  this.getList(this.pagination.current_page + 1);
			}
		},
		onPullDownRefresh() {
			this.onRefresh()	
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 500);
		},
		methods: {
			onRefresh(){
				this.pagination = pagination
				this.getList()
			},
			toPage(url){
				uni.navigateTo({
					url
				})
			},
			getList(page = 1){
				this.loading = 'loading';
				getActivityList({page}).then( res => {
					let list = this.pagination.data.concat(res.data.data);
					this.pagination = {
					  ...res.data,
					  data: list,
					};
					this.loading = 'none';
					if(!list.length) return this.loading = 'empty';
					 if (this.pagination.current_page < this.pagination.last_page) {
					   this.loading = 'none';
					 } else {
					   this.loading = 'nomore';
					 }
					 uni.stopPullDownRefresh();
				}).catch( err => {
					
				})
			},
		}
	}
</script>

<style>

</style>
